//
//  CommonUnit.h
//  XiaoZhen
//
//  Created by 李彦宏 on 2018/8/31
//  Copyright © 2017年 Toocms. All rights reserved.
//

#ifndef CommonUnit_h
#define CommonUnit_h

#define Screen_width  ([UIScreen mainScreen].bounds.size.width)
#define Screen_Height  ([UIScreen mainScreen].bounds.size.height)

#define Kscreen_width  ([UIScreen mainScreen].bounds.size.width)
#define Kscreen_Height  ([UIScreen mainScreen].bounds.size.height)

#define MDK_SCREEN_WIDTH  [[UIScreen mainScreen] bounds].size.width
#define SafeAreaTopHeight (isIPhoneXSeries() ? 88 : 64)//nav高度
#define SafeH (isIPhoneXSeries() ? 44 : 20)
#define SafeAreaBoHttomHeight (isIPhoneXSeries() ? 34 : 0)//苹果X适配底部间距
#define StatusBarHeight (isIPhoneXSeries() ? 44 : 20)//苹果X适配低部间距
#define SafeAreaTabBarHeight (isIPhoneXSeries() ? 84 : 50)//tab高度

#define SafeAreaTowFourHeight (isIPhoneXSeries() ? 24 : 0)//苹果X适配顶部间距


#pragma -mark ————————————————————device  info————————————————————
#define IPHONEX                 ([[UIScreen mainScreen] bounds].size.height >= 812.0)

#define NAVBar_height (IPHONEX?88:64)
#define TaBar_height (IPHONEX?83:49)
#define StateBar_height (IPHONEX?44:20)
#define Search_hight (IPHONEX?10:10)

#define SCREEN_WIDTH ([UIScreen mainScreen].bounds.size.width)
#define SCREEN_HEIGHT ([UIScreen mainScreen].bounds.size.height)

/**自适应高度*/
#define  dynamicHeight [[UIScreen mainScreen] bounds].size.height / 676
/**
 *  整个屏幕高度
 */
#define MDK_SCREEN_HEIGHT [[UIScreen mainScreen] bounds].size.height

/**
 *  16进制颜色转换
 */
#define UIColorFromRGB(rgbValue) [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 green:((float)((rgbValue & 0xFF00) >> 8))/255.0 blue:((float)(rgbValue & 0xFF))/255.0 alpha:1.0]
#pragma -mark ———————————————————商城产品————————————————————
/**主题颜色*/
#define ThemeColor HexColor(@"#ff1913")
/**灰色背景*/
#define Graycolor HexColor(@"#eaeaea")
//用户ID
#define userID  [[NSUserDefaults standardUserDefaults]objectForKey:@"MID"]
//是否设置密码
#define IsPayPass [[NSUserDefaults standardUserDefaults]objectForKey:@"is_pay_pass"]

#define TSUserDef(Key) [[NSUserDefaults standardUserDefaults] objectForKey:(Key)]
//小红点数量
#define TSbadcount TSUserDef(@"badcount")

#define RGBColor(r, g, b)  [UIColor colorWithRed:(r) / 255.0 green:(g) / 255.0 blue:(b) / 255.0 alpha:1]
#define RGBColor2(r, g, b, a)  [UIColor colorWithRed:(r) / 255.0 green:(g) / 255.0 blue:(b) / 255.0 alpha:(a)]


#define HpercentOfSeven [[UIScreen mainScreen] bounds].size.height / 676
#define WpercentOfSeven [[UIScreen mainScreen] bounds].size.width / 375

#define kScreenBounds [UIScreen mainScreen].bounds
/// 十六进制颜色
#define HexColor(hexString) [UIColor hexColor:(hexString)]

#define kScreenHeigth [[UIScreen mainScreen] bounds].size.height
#define kNScreenHeigth [[UIScreen mainScreen] bounds].size.height - 64
#define kScreenWidth [[UIScreen mainScreen] bounds].size.width
#define kHalfScreenHeigth [[UIScreen mainScreen] bounds].size.height * 0.5
#define kHalfScreenWidth [[UIScreen mainScreen] bounds].size.width * 0.5
#define User_is_login [User sharedUser].isLogin
#define USER [User sharedUser]


#define User_m_id [User sharedUser].userInfo.m_id

#define SVShowError(message) [SVProgressHUD showError:(message)]
#define SVShowSuccess(message)[SVProgressHUD showSuccess:(message)]
#define SLFail SVShowError(@"网络连接失败");
#define ThemeOrangeColor HexColor(@"ea4a96")

#define WeakSelf __weak typeof(self) wself = self;

// 背景颜色
#define GlobalBackgroundColor self.view.backgroundColor = RGBColor(240, 240, 240);

/// CGRect
#define Rect(x, y, w, h) CGRectMake((x), (y), (w), (h))
/// CGSize
#define Size(w, h) CGSizeMake((w), (h))
/// CGPoint
#define Point(x, y) CGPointMake((x), (y))


static NSString *ThemeCellId = @"ThemeCellId";
static NSString *ActivityCellId = @"ActivityCellId";
static NSString *headerID = @"headerID";
static NSString *AdHeaderViewId = @"AdHeaderViewId";
static CGFloat SwitchOptionViewHeight = 50;


#define ChouKuanPicHeight (kScreenWidth - 60 - 15 - 8) / 5.0
#define FivePicCellHeight   (kScreenWidth - 30 - 8)/ 5.0


#define getTextForKey(key) [YJXChangeLanguage.bundle localizedStringForKey:key value:nil table:@"Language"]
static inline BOOL isIPhoneXSeries(){
    BOOL iPhoneXSeries = NO;
    if (UIDevice.currentDevice.userInterfaceIdiom != UIUserInterfaceIdiomPhone) {
        return iPhoneXSeries;
    }
    
    if (@available(iOS 11.0, *)) {
        UIWindow *mainWindow = [[[UIApplication sharedApplication] delegate] window];
        if (mainWindow.safeAreaInsets.bottom > 0.0) {
            iPhoneXSeries = YES;
        }
    }
    
    return iPhoneXSeries;
}
//tableview偏移类型
typedef NS_ENUM(NSInteger, OffsetType) {
    OffsetTypeMin,
    OffsetTypeCenter,
    OffsetTypeMax,
};
//空值判断
static inline BOOL IsEmptyValue(id _Nullable thing) {
    return thing == nil
    || ([thing respondsToSelector:@selector(length)]
        && [(NSData *) thing length] == 0)
    || ([thing respondsToSelector:@selector(count)]
        && [(NSArray *) thing count] == 0)
    || ([thing isKindOfClass:[NSNull class]]);
}
#pragma mark -  界面跳转枚举常量
// 从哪个界面跳转到添加银行卡
typedef NS_ENUM(NSInteger, AddBankCardFromWhere) {
    AddBankCardFromVerifyProject,
    AddBankCardFromMyWithdraw,
    AddBankCardFromMyCard
} ;

// 发起项目之后选择的验证类型
typedef NS_ENUM(NSInteger, ProjectVerifyType) {
    ProjectVerifySelf,
    ProjectVerifyParentOrBrother,
    ProjectVerifyCouple,
    ProjectVerifyOrganiztion
} ;

// 发起项目之后选择的验证类型
typedef NS_ENUM(NSInteger,PublishProjectType) {
    PublishProjectChangXian,
    PublishProjectDream
} ;


// 发起项目之后选择的验证类型
typedef NS_ENUM(NSInteger,ProjectType) {
    ProjectTypeWeiLove,
    ProjectTypeChangXian,
    ProjectTypeDream
} ;


// 地址选择页从哪里进入
typedef NS_ENUM(NSInteger,AddressPageFromWhere) {
    AddressPageFromSupport,
    AddressPageFromHospital,
    AddressPageFromPersonCenter
} ;

// 发布界面从哪里进入
typedef NS_ENUM(NSInteger,PublishPageFromWhere) {
    PublishPageFromPublish,
    PublishPageFromEdit
} ;

// 查看项目界面从哪里进入
typedef NS_ENUM(NSInteger,CheckDetailProjectPageFromWhere) {
    CheckDetailProjectPageFromPersonalCenter,
    CheckDetailProjectPageFromPublishSuccess
} ;


//查看帮助界面从哪里进入
typedef NS_ENUM(NSInteger,PublishReadmePageFromWhere) {
    PublishReadmePageFromPublishController,
    PublishReadmePageFromLittleLoveController
} ;

//登录界面从哪里进入
typedef NS_ENUM(NSInteger,LoginPageFromWhere) {
    LoginPageFromOther,
    LoginPageFromTabBar
} ;

//红包界面从哪里进入
typedef NS_ENUM(NSInteger,MyEnvelopePageFromWhere) {
    MyEnvelopePageFromPersonalCenter,
    MyEnvelopePageFromSupport
} ;


#pragma mark -  通知常量

// 登录成功
static NSString *LoginSuccessNotification = @"LoginSuccessNotification";

// tabbar发布按钮点击通知
static NSString *PresentPublishControllerNotification = @"PresentPublishControllerNotification";

//加入购物车小红点变化通知
static NSString *CartbadgeValueNotification = @"CartbadgeValueNotification";

// 订单修改成功后发出的刷新数据的通知
static NSString *OrderDidUpdateNotification = @"OrderDidUpdateNotification";

// 下线重新登录发出的通知
static NSString *ReLoginNotification = @"ReLoginNotification";

// 详情界面支持者和动态点击查看更多的通知
static NSString *HisSupportOrDynamicLookMoreNotification = @"HisSupportOrDynamicLookMoreNotification";

// 5张图片格点击查看大图的通知
static NSString *ShowPhotoBroswerNotification = @"ShowPhotoBroswerNotification";

// 微信支付成功的通知
static NSString *ReturnSucceedPayNotification = @"ReturnSucceedPayNotification";

// 微信支付失败的通知
static NSString *ReturnFailedPayNotification = @"ReturnFailedPayNotification";

// 选择了一个省市区的通知，用于支持界面和个人中心添加地址
static NSString *DidSelectedProvinceCityCountyNotification = @"DidSelectedProvinceCityCountyNotification";

// 环信收到消息时改变消息控制器下方bdgeValue的通知
static NSString *ShouldCgangeMsgVCBadgeValueNotification = @"ShouldCgangeMsgVCBadgeValueNotification";



/// 定义没有返回值的block
typedef void (^VoidBlcok)(void);

/// 定义带一个NSDictionary参数的block
///
/// @param dict NSDictionary
typedef void (^DictionaryBlcok)(NSDictionary *dict);

/// 定义带一个array参数的block
///
/// @param array NSArray
typedef void (^ArrayBlcok)(NSArray *array);

/// 定义带一个NSString参数的block
///
/// @param string NSString
typedef void (^StringBlcok)(NSString *string);

#define IfUserIsNotLogin \
if (!User_is_login) { \
TSSignInViewController *vc = [TSSignInViewController new];\
[self.navigationController pushViewController:vc animated:YES]; \
return; \
}

/// 验证是文字是否输入
///
/// @param __Text    文字长度
/// @param __Message 错误提示
#define SLVerifyText(__TextLength, __Message)\
if (!__TextLength) {\
SVShowError(__Message);\
return;\
}

/// 验证手机正则
///
/// @param __Text    文字
/// @param __Message 错误提示
#define SLVerifyPhone(__Phone, __Message)\
if (![__Phone validateMobile]) {\
SVShowError(__Message);\
return;\
}

/// 验证邮箱正则
///
/// @param __Text    文字
/// @param __Message 错误提示
#define SLVerifyEmail(__Email, __Message)\
if (![__Email validateEmail]) {\
SVShowError(__Message);\
return;\
}

/// 验证密码正则
///
/// @param __Text    文字
/// @param __Message 错误提示
#define SLVerifyPassword(__Password, __Message)\
if (![__Password validatePassword]) {\
SVShowError(__Message);\
return;\
}

/// 验证条件
#define SLAssert(Condition, Message)\
if (!(Condition)) {\
SVShowError(Message);\
return;\
}

#define SLEndRefreshing(__ScrollView)\
if ([__ScrollView.mj_footer isRefreshing]) {\
[__ScrollView.mj_footer endRefreshing];\
}\
if ([__ScrollView.mj_header isRefreshing]) {\
[__ScrollView.mj_header endRefreshing];\
}


#define SLReleaseView(__View) { \
[(__View) removeFromSuperview];\
(__View) = nil;}


#define SLLazyMutableArray(_array) \
return !(_array) ? (_array) = [NSMutableArray array] : (_array);

#define SLLazyArray(_array)    \
return !(_array) ? (_array) = [NSArray array] : (_array);

#define SLLazyMutableDictionary(_dictionary) \
return !(_dictionary) ? (_dictionary) = [NSMutableDictionary dictionary] : (_dictionary);

#define SLLazyDictionary(_dictionary) \
return !(_dictionary) ? (_dictionary) = [NSDictionary dictionary] : (_dictionary);

#define Fit375(num) ((num)*kScreenWidth/375.00)

#define getImageOfid(num) [NSString stringWithFormat:@"http://api.tebaihui.net/System/loadImg/id/%@",num]

#endif
